#!/usr/bin/python
# Test interpreter
# by Albert Zeyer, 2011
# code under GPL

import sys, os, os.path
if __name__ == '__main__':
    MyDir = os.path.dirname(sys.argv[0]) or "."
    sys.path.append(MyDir + "/../../cinterpreter") # so that 'import cinterpreter' works as expected

def c2ctype(source,name,state=None):
    import cinterpreter
    if state is None:
        state = cinterpreter.State()
        state.autoSetupSystemMacros()
        state.autoSetupGlobalIncludeWrappers()
        cinterpreter.parse_code(source, state)
    for v in state.contentlist:
        if v.name == name:
            return v.getCType(state)
    return None
s="""
typedef struct __st_aml_block_header{
    //16
    unsigned int   dwMagic;       //"@AML"
    unsigned int   nTotalSize;    //total size: sizeof(hdr)+
                                  //  nSigLen + nDataLen
    unsigned char  bySizeHdr;     //sizeof(st_aml_block)
    unsigned char  byRootKeyIndex;//root key index; only romcode
                                  //  will use it, others just skip
    unsigned char  byVerMajor;    //major version
    unsigned char  byVerMinor;    //minor version

    unsigned char  szPadding1[4]; //padding???

    //16+16
    unsigned int   nSigType;      //e_aml_sig_type : AML_SIG_TYPE_NONE...
    unsigned int   nSigOffset;    //sig data offset, include header
    unsigned int   nSigLen;       //sig data length
    //unsigned char  szPadding2[4]; //padding???
    unsigned int   nCHKStart;     //begin to be protected with SHA2

    //32+16
    unsigned int   nPUKType;     //e_aml_data_type : AML_DATA_TYPE_PROGRAM
    unsigned int   nPUKOffset;   //raw data offset, include header
    unsigned int   nPUKDataLen;  //raw data length
    //unsigned char  szPadding4[4]; //padding???
    unsigned int   nCHKSize;     //size to be protected with SHA2

    //48+16
    unsigned int   nDataType;     //e_aml_data_type : AML_DATA_TYPE_PROGRAM
    unsigned int   nDataOffset;   //raw data offset, include header
    unsigned int   nDataLen;      //raw data length
    unsigned char  szPadding3[4]; //padding???

    //64
} st_aml_block_header;
"""
if __name__ == '__main__':
    x=c2ctype(s,"st_aml_block_header")
    print(dir(x),type(x))
    print x._fields_

